"""

"""

import os
import logging
from kivymd.app import MDApp
from kivymd.uix.screenmanager import MDScreenManager

from ..core import setup_logging
from .screens.main_screen import MainScreen
from .screens.upload_screen import UploadScreen
from .screens.processing_screen import ProcessingScreen
from .screens.result_screen import ResultScreen
from .screens.settings_screen import SettingsScreen

class MobileApp(MDApp):
    """"""
    
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.title = ""
        self.theme_cls.primary_palette = "Blue"
        self.theme_cls.theme_style = "Light"
        
        # 
        setup_logging('INFO')
        self.logger = logging.getLogger(__name__)
        
        # 
        self.screen_manager = None
        
        # 
        self.settings_data = self._load_default_settings()
    
    def build(self):
        """"""
        self.logger.info("")
        
        # 
        self.screen_manager = MDScreenManager()
        
        # 
        self.screen_manager.add_widget(MainScreen(name='main'))
        self.screen_manager.add_widget(UploadScreen(name='upload'))
        self.screen_manager.add_widget(ProcessingScreen(name='processing'))
        self.screen_manager.add_widget(ResultScreen(name='result'))
        self.screen_manager.add_widget(SettingsScreen(name='settings'))
        
        return self.screen_manager
    
    def navigate_to(self, screen_name: str):
        """"""
        if self.screen_manager:
            self.screen_manager.current = screen_name
    
    def _load_default_settings(self):
        """"""
        return {
            'whisper_model': 'base',
            'ollama_model': 'qwen2:7b',
            'ollama_host': 'localhost',
            'ollama_port': 11434,
            'language': 'auto',
            'summary_style': 'detailed',
            'output_formats': ['txt', 'srt', 'json'],
            'device': 'auto',
            'chunk_duration': 600,
            'auto_cleanup': True,
            'output_dir': './output',
            'temp_dir': './temp'
        }

def main():
    """"""
    app = MobileApp()
    app.run()

if __name__ == "__main__":
    main()